﻿// // --------------------------------------------------------------------------------------------------------------------
// // <copyright file="Ribbon.cs" company="Collaboris">
// //   Copyright Collaboris
// // </copyright>
// // <summary>
// //   
// // </summary>
// // --------------------------------------------------------------------------------------------------------------------

namespace Collaboris.ShareTest.SharePoint2010.Actions
{
    #region

    using Collaboris.ShareTest.Core;

    using OpenQA.Selenium;
    using OpenQA.Selenium.Remote;

    #endregion

    /// <summary>
    /// 	TODO: Update summary.
    /// </summary>
    public class Ribbon
    {
        #region Public Methods

        /// <summary>
        /// 	Clicks "Insert" on the Ribbon
        /// </summary>
        /// <param name = "webDriver">
        /// </param>
        public static void Click_Insert_Tab(RemoteWebDriver webDriver)
        {
            Logger.LogMessage("Clicking Ribbon Insert tab");
            webDriver.FocusAndClick(
                By.XPath("//li[@id='" + Common.Map.Ribbon.RibbonEditingToolsInsertTabId + "']/a/span"));
        }

        /// <summary>
        /// 	Clicks the "Page" tab in the Ribbon
        /// </summary>
        /// <param name = "webDriver">
        /// </param>
        public static void Click_Page_Tab(RemoteWebDriver webDriver)
        {
            Logger.LogMessage("Clicking Ribbon Wiki Page Tab");
            webDriver.FocusAndClick(By.Id("ctl00_PageStateActionButton"));
        }

        #endregion

        /// <summary>
        /// 	The insert.
        /// </summary>
        public static class Insert
        {
            #region Public Methods

            /// <summary>
            /// 	The click_ ribbon_ insert_ save and close_ button.
            /// </summary>
            /// <param name = "webDriver">
            /// 	The web driver.
            /// </param>
            public static void Click_SaveAndClose_Button(RemoteWebDriver webDriver)
            {
                Logger.LogMessage("Clicking Ribbon Save And Close button");

                // FocusAndClick(webDriver, By.Id(Map.RibbonEditingToolsSaveAndCloseButtonId));
                webDriver.WaitForElementNotPresent(By.Id(Common.Map.Ribbon.RibbonEditingToolsSaveAndCloseButtonId));
                webDriver.Focus(webDriver.FindElement(By.Id(Common.Map.Ribbon.RibbonEditingToolsSaveAndCloseButtonId)));
                webDriver.ClickWithWait(By.Id(Common.Map.Ribbon.RibbonEditingToolsSaveAndCloseButtonId));
            }

            /// <summary>
            /// 	Click the Web Part icon on the "insert" menu in the ribbon.
            /// </summary>
            /// <param name = "webDriver">
            /// </param>
            public static void Click_WebPart_Button(RemoteWebDriver webDriver)
            {
                Logger.LogMessage("Clicking Ribbon Insert tab");
                webDriver.FocusAndClick(By.Id(Common.Map.Ribbon.RibbonInsertWebPartButtonId));
            }

            #endregion
        }

        /// <summary>
        /// 	The web part menu.
        /// </summary>
        public static class WebPartMenu
        {
            #region Public Methods

            /// <summary>
            /// 	Adds the selected web part to the page.
            /// </summary>
            /// <param name = "webDriver">
            /// </param>
            public static void Click_Add_Button(RemoteWebDriver webDriver)
            {
                Logger.LogMessage("Clicking Web Part Add Button");
                webDriver.FocusAndClick(
                    By.XPath(
                        @"//div[@class='ms-wpadder-buttonArea ms-wpadder-zoneArea']/button[@onclick='WPAdder.addSelectedItemToPage();return false']"));
            }

            /// <summary>
            /// 	When the Web Part Picker is on display click a category
            /// </summary>
            /// <param name = "webDriver">
            /// </param>
            /// <param name = "webPartCategoryTitle">
            /// </param>
            public static void Click_Category(RemoteWebDriver webDriver, string webPartCategoryTitle)
            {
                Logger.LogMessage("Clicking Web Part Category");
                webDriver.FocusAndClick(
                    By.XPath(
                        "//table[@id='" + Common.Map.Ribbon.WebPartPickerId + "']/tbody/tr/td/div/div[@title='"
                        + webPartCategoryTitle + "']"));
            }

            /// <summary>
            /// 	Clicks the web part Item in questions
            /// </summary>
            /// <param name = "webDriver">
            /// </param>
            /// <param name = "webPartItem">
            /// </param>
            public static void Click_WebPart(RemoteWebDriver webDriver, string webPartItem)
            {
                Logger.LogMessage("Clicking Web Part Item");
                webDriver.FocusAndClick(By.XPath("//div[@title='" + webPartItem + "']"));
            }

            #endregion
        }
    }
}